package com.gxa.luckin.user.controller;

import com.gxa.luckin.core.pojo.User;
import com.gxa.luckin.core.utils.JsonResult;
import com.gxa.luckin.user.service.UserService;
import com.gxa.luckin.user.service.impl.UserServiceImpl;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private RedisTemplate redisTemplate;
//    @Resource
//    UserService userService;
    @Resource
    UserService userService;
    @PostMapping("/select")
    public JsonResult select(@RequestBody User user) throws IllegalAccessException {
        List<User> users = userService.selectByLike(user);
        System.out.println(users);
        JsonResult jsonResult=new JsonResult();
        if(users!=null){
            jsonResult.setCode("1");
            jsonResult.setData(users);
        }else {
            jsonResult.setCode("0");
            jsonResult.setMsg("啥也没有");
        }
        return jsonResult;
    }
    @PostMapping("/status")
    public JsonResult status(@RequestParam Long id){
        JsonResult jsonResult=new JsonResult();
        User user = userService.selectById(id.intValue());
        Integer status = user.getStatus();
        System.out.println(status);
        if(status.equals(1)){
            user.setStatus(0);
            userService.updateById(user);
            jsonResult.setCode("1");
            jsonResult.setMsg("修改成功");
        }
        else if(status.equals(0)){
            user.setStatus(1);
            userService.updateById(user);
            jsonResult.setCode("1");
            jsonResult.setMsg("修改成功");
        }
        else {
            jsonResult.setCode("0");
            jsonResult.setMsg("操作失败");
        }
        return jsonResult;
    }
}
